<template>
	<view class="page">
		<uv-navbar
			:leftIconColor="navstyle.txtColor"
			:titleStyle="titleStyle"
			:title="navstyle.title"
			:leftIcon="navstyle.leftIcon"
			:bgColor="navstyle.bgColor"
			:fixed="false" 
			@leftClick="leftClick"
			:safeAreaInsetTop="false">
		</uv-navbar>
		<view class="retrieve">
			<view class="listinput">
				<uv-text text="姓名"></uv-text>
				<uv-input  border="surround"  style="padding: 3px 9px;" placeholder="请输入姓名" v-model="userform.name" ></uv-input>
			</view>
			<button class="exitbtn" @click="submitClick">保存</button>
		</view>
	</view>
	
</template>

<script>
	import {saveInfo} from '@/api/user.js';
	export default{
		data(){
			return{
				navstyle: {
					title: "修改姓名",
					txtColor: "#333333",
					bgColor: "#FFFFFF",
					leftIcon: "arrow-left"
				},
				titleStyle: {
					fontWeight: 700
				},
				userform:{
					name:""
				}
			}
		},
		methods:{
			leftClick() {
				uni.reLaunch({
				  url: '/pages/user/account' // 替换成上一页的路径
				});
			},
			submitClick(){
				if(!this.userform.name){
					uni.showToast({
						title: '请输入姓名',
						duration: 2000
					});
					return
				}
				saveInfo({
					username:this.userform.name,
				}).then(response=>{
					if(response.code==1){
						uni.reLaunch({
						  url: '/pages/user/account' // 替换成上一页的路径
						});
						uni.showToast({
							title: response.msg,
							icon:'success',
							duration: 2000
						});
					}
				})
			}
		}
	}
</script>

<style>
	.page{
		width: 100%;
		height: 100%;
	    background-color: #fafafa;
	}
	.retrieve{
	    display: flex;
	    flex-direction: column;
	    font-size: 14px;
	    color: #333;
	}
	.listinput {
	    padding: 4px 5%;
	    font-size: 14px;
	    color: #585858;
	    line-height: 42px;
	}
	.exitbtn{
	    width: 80%;
	    border-radius: 50px;
	    background: linear-gradient(135deg, #d66c6b, #ed6266);
	    font-size: 14px;
	    margin: 32px auto 0 auto;
	    color: #fff;
	    padding: 3px 0;
	    border: none;
	}
</style>